#!/bin/sh
# parameter 1: sql
# parameter 2: database host
# parameter 3: database port
# parameter 4: other mysql client settings

set -e

sql=${1}

host=127.0.0.1
if [ $# -gt 1 ]; then
	shift
	host=${1}
fi

port=4000
if [ $# -gt 1 ]; then
	shift
	port=${1}
fi

if [ $# -gt 1 ]; then
	shift
	other=${*}
fi

prepare="set global tidb_enable_clustered_index = 'int_only';"

echo "[$(date)] Executing SQL: ${sql}" >"$OUT_DIR/sql_res.$TEST_NAME.txt"

mysql -uroot -h${host} -P${port} ${other} --default-character-set utf8mb4 -E -e "${prepare}" >"$OUT_DIR/sql_res.$TEST_NAME.txt"
mysql -uroot -h${host} -P${port} ${other} --default-character-set utf8mb4 -E -e "${sql}" >"$OUT_DIR/sql_res.$TEST_NAME.txt"
